# $Id: PKGBUILD 78358 2012-10-17 15:20:09Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=ultimate-ircd
pkgver=3.0.2
pkgrel=6
pkgdesc="ultimate irc server"
arch=(i686 x86_64)
url="http://www.shadow-realm.org/"
license=("GPL")
depends=(glibc)
makedepends=(patch)
conflicts=(ircd)
provides=(ircd)
backup=()
install=ircd.install
source=(http://downloads.sourceforge.net/sourceforge/ultimate/Ultimate$pkgver.tar.bz2
	ultimate-ircd
	ultimate-ircd.service
	ultimate-ircd.tmpfiles
	conf-fix.patch)
md5sums=('8bc14b97d22a3ce3415cc0540ae459f6'
         'cf6ab14d8dd8805342b70a9beb01c9af'
         '526fd78018b9b011787e4e9012437116'
         'e51723ab29e7a3ddc3589846815de0c9'
         '5e0f2a02e12675ac070a148c3234e111')

build() {
  cd $srcdir/Ultimate$pkgver
  ./configure --prefix=/usr --enable-chinese-nick

  for i in `find -type f -name Makefile`; do
    echo Patching $i...
    sed -i "s#prefix		= /usr#prefix		= $pkgdir/usr#" $i
    sed -i "s#libexecdir	= \${bindir}#libexecdir	= $pkgdir/usr/lib/ircd#" $i
    sed -i "s#sysconfdir	= \${prefix}/etc#sysconfdir	= $pkgdir/etc/ircd#" $i
    sed -i "s#localstatedir	= \${prefix}#localstatedir	= $pkgdir/var#" $i
    sed -i "s#networksubdir   = \${prefix}/etc/networks#networksubdir   = $pkgdir/etc/ircd/networks#" $i
    sed -i "s#\$(localstatedir)/logs#\$(localstatedir)/log/ircd#" $i
  done

  cd include && patch -N <../../conf-fix.patch && cd ..
  make || return 1

  mkdir -p $pkgdir/usr/bin
  mkdir -p $pkgdir/var/log/ircd
  mkdir -p $pkgdir/etc/ircd/networks
  make install
  rm -f $pkgdir/usr/ircd
  rm -f $pkgdir/usr/kill
  rm -f $pkgdir/usr/rehash
  cd $pkgdir/usr/bin
  mv mkpasswd irc-mkpasswd
  mv ssl-cert.sh irc-ssl-cert.sh
  mv ssl-search.sh irc-ssl-search.sh
  install -D -m 0755 $srcdir/ultimate-ircd $pkgdir/etc/rc.d/ultimate-ircd
  install -d -m 0755 $pkgdir/var/lib/ircd
  install -Dm0644 $srcdir/$pkgname.service $pkgdir/usr/lib/systemd/system/$pkgname.service
  install -Dm0644 $srcdir/$pkgname.tmpfiles $pkgdir/usr/lib/tmpfiles.d/$pkgname.conf
}
